<template>
  <view class="contentBd">
    <scroll-view scroll-x class="tabList">
      <view
        @click="$emit('handle', 'tab', item)"
        :class="['item', active === item.id ? 'active' : '']"
        v-for="(item, index) of tab"
        :key="index"
      >
        {{ item.name }}
      </view>
    </scroll-view>

    <view
      class="popup-list-item"
      v-for="(sku, i) in items"
      :key="i"
      @click="$emit('handle', 'detail', sku)"
    >
      <view class="good-info">
        <image class="good-pic" :src="sku.cover_pic" mode="" />
        <view class="info-section">
          <view class="good-name">{{ sku.name }}</view>
          <view class="good-count">
            <text>{{ sku.userCount || 0 }}</text> 人正在参与</view
          >
          <view class="good-min-price">
            最低可砍至
            <view class="good-price">
              <text>￥</text>
              <text>{{ sku.price | priceBeforeZero }}</text>
              <text>{{ sku.price | priceAfterZero }}</text>
            </view>
          </view>
          <view class="good-select">
            <view class="good-select-let"
              >原价
              <view class="good-price">
                <text>￥</text>
                <text style="font-weight: normal">{{
                  sku.oldPrice | priceBeforeZero
                }}</text>
                <text>{{ sku.oldPrice | priceAfterZero }}</text>
              </view>
            </view>

            <view class="good-btn">立即参与</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    tab: {
      type: Array,
      default: () => {
        return [];
      },
    },

    items: {
      type: Array,
      default: () => {
        return [];
      },
    },

    active: {
      type: [String, Number],
      default: "",
    },
  },

  filters: {
    priceBeforeZero(val) {
      if (!val) val = "";
      if (val.indexOf(".") < 0) return `${val}.`;
      return val.substr(0, val.indexOf("."));
    },
    priceAfterZero(val) {
      if (!val) val = "";
      if (val.indexOf(".") < 0) return "00";
      return val.substr(val.indexOf("."), val.length);
    },
  },

  data() {
    return {};
  },
};
</script>

<style lang="less" scoped>
.contentBd {
  padding: 0 24rpx;
}

.tabList {
  position: sticky;
  left: 0;
  top: 84rpx;
  right: 0;
  background: #f0f0f0;
  z-index: 4;
  padding: 10rpx 0;
  white-space: nowrap;

  .item {
    position: relative;
    display: inline-block;
    margin-right: 40rpx;
    padding-bottom: 8rpx;
    vertical-align: middle;
    text-align: center;
    font-size: 28rpx;
    color: #262626;

    &.active {
      font-weight: bold;

      &:after {
        content: "";
        position: absolute;
        left: 50%;
        bottom: 0;
        margin-left: -17rpx;
        width: 34rpx;
        height: 6rpx;
        background: #f0250e;
      }
    }
  }
}

.popup-list-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 24rpx;
  padding: 24rpx 26rpx;
  background: #fff;
  border-radius: 24rpx;

  &:first-of-type {
    margin-top: 16rpx;
  }

  .good-info {
    position: relative;
    width: 100%;
    display: flex;
    align-items: flex-start;
    .good-pic {
      display: block;
      width: 224rpx;
      height: 224rpx;
      background: #f2f2f2;
      border-radius: 10rpx;
      display: block;
      margin-right: 20rpx;
      flex-shrink: 0;
    }
    .info-section {
      flex: 1;
      overflow: hidden;

      .good-name {
        font-size: 28rpx;
        font-family: PingFang SC;
        font-weight: 600;
        line-height: 40rpx;
        max-height: 80rpx;
        color: #262626;
        display: -webkit-box;
        white-space: normal;
        text-overflow: ellipsis;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        word-break: break-all;
        overflow: hidden;
      }

      .good-sku {
        max-width: 40.27vw;
        font-size: 3.2vw;
        font-weight: 400;
        line-height: 4.27vw;
        color: #999999;
        margin-top: 1.07vw;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
      }
    }
  }
}

.good-price {
  display: flex;
  align-items: baseline;
  font-size: 24rpx;

  text:nth-child(2) {
    font-size: 32rpx;
    font-weight: 600;
  }
}

.popup-list-item:last-child {
  margin-bottom: 0;
}

.good-btn {
  width: 180rpx;
  height: 60rpx;
  text-align: center;
  line-height: 60rpx;
  background: linear-gradient(90deg, #ff1b22 0%, #ff7333 100%);
  border-radius: 32px;
  font-size: 28rpx;
  font-weight: bold;
  color: #fff;
}

.good-count {
  padding: 10rpx 0 14rpx;
  color: #8c8c8c;
  font-size: 24rpx;

  text {
    color: #f0250e;
  }
}

.good-min-price {
  position: relative;
  top: 8rpx;
  display: flex;
  align-items: flex-end;
  color: #f0250e;
  line-height: 1;
  font-size: 24rpx;

  .good-price text {
    color: #f0250e;
  }
}

.good-select {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;

  .good-select-let {
    flex: 1;
    display: flex;
    align-items: flex-end;
    padding-bottom: 4rpx;
    overflow: hidden;
    font-size: 24rpx;
    color: #8c8c8c;

    .good-price {
      position: relative;

      &:after {
        content: "";
        position: absolute;
        left: 0;
        top: 50%;
        width: 100%;
        height: 1px;
        background: #8c8c8c;
      }

      text {
        font-size: 24rpx;

        text:nth-child(2) {
          font-size: 24rpx;
          font-weight: normal;
        }
      }
    }
  }
}
</style>
